package org.summerframework.component.security.session.config;

import org.summerframework.component.security.core.role.AuthenticationPermissionsService;
import org.summerframework.component.security.core.role.AuthenticationService;
import org.summerframework.component.security.core.service.LoginLogService;
import org.summerframework.component.security.core.service.LogoutService;
import org.summerframework.component.security.core.service.SessionService;
import org.summerframework.component.security.core.service.UserLoginService;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.session.SessionAutoConfiguration;
import org.springframework.boot.autoconfigure.session.SessionProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * redis session 配置
 *
 * @author 石超
 * @version v1.0.0
 */
@Configuration
@ComponentScan("org.summerframework.component.security.session.service.impl")
@EnableConfigurationProperties({ServerProperties.class, SessionProperties.class})
@AutoConfigureBefore(SessionAutoConfiguration.class)
public class HttpSessionConfig {

    @Bean
    @ConditionalOnMissingBean(UserLoginService.class)
    public UserLoginService userLoginService() {
        return new UserLoginService() {
        };
    }

    @Bean
    @ConditionalOnMissingBean(SessionService.class)
    public SessionService sessionService() {
        return new SessionService() {
        };
    }

    @Bean
    @ConditionalOnMissingBean(LoginLogService.class)
    public LoginLogService defaultLoginLogService() {
        return new LoginLogService() {
        };
    }

    @Bean
    @ConditionalOnMissingBean(LogoutService.class)
    public LogoutService logoutService() {
        return new LogoutService() {
        };
    }

    @Bean
    @ConditionalOnMissingBean(AuthenticationService.class)
    public AuthenticationService authenticationService() {
        return new AuthenticationService() {
        };
    }

    @Bean
    @ConditionalOnMissingBean(AuthenticationPermissionsService.class)
    public AuthenticationPermissionsService authenticationPermissionsService() {
        return new AuthenticationPermissionsService() {
        };
    }
}
